<?php
//	require_once '../query/dbquery.php';
	require_once '../query/config.php';
	$agent = $_REQUEST['agent'];
	if ( isset($agent) && $agent == "add" ){
		$agentname 		= $_REQUEST['agentname'];
		$telephone 		= $_REQUEST['telephone'];
		$email			= $_REQUEST['email'];
		$address		= $_REQUEST['address'];
		$discount2	 	= $_REQUEST['discount2'];
		$discount3		= $_REQUEST['discount3'];
		$discount4		= $_REQUEST['discount4'];
		$discount5		= $_REQUEST['discount5'];
		$win_factor2	= $_REQUEST['win_factor2'];
		$win_factor3	= $_REQUEST['win_factor3'];
		$win_factor4	= $_REQUEST['win_factor4'];
		$win_factor5	= $_REQUEST['win_factor5'];		
		$id 		= $_REQUEST['id'];
		$cdate	=  $mdate = date('Y-m-d');				
		$publish 	= 1;
		
		new dbConnect();
		if ($id == 0){
			$query = "INSERT INTO `tagent` SET `agent_name` = '".$agentname."', `phone` = '".$telephone."',`email` = '".$email."', `address` = '".$address."'".
					", `discount2digit` = '".$discount2."', `discount3digit` = '".$discount3."', `discount4digit` = '".$discount4."', `discount5digit` = '".$discount5."'".
					", `win_factor2digit` = '".$win_factor2."', `win_factor3digit` = '".$win_factor3."', `win_factor4digit` = '".$win_factor4."', `win_factor5digit` = '".$win_factor5."'".
					", `cdate` = '".$cdate."', `publish` = $publish";	
			if (mysql_query($query)){
				echo mysql_insert_id();
			}else{
				echo "0";
			}
		}else{			
			$query = "UPDATE `tagent` SET `agent_name` = '".$agentname."', `phone` = '".$telephone."',`email` = '".$email."', `address` = '".$address."'".
					", `discount2digit` = '".$discount2."', `discount3digit` = '".$discount3."', `discount4digit` = '".$discount4."', `discount5digit` = '".$discount5."'".
					", `win_factor2digit` = '".$win_factor2."', `win_factor3digit` = '".$win_factor3."', `win_factor4digit` = '".$win_factor4."', `win_factor5digit` = '".$win_factor5."'".
					", `cdate` = '".$cdate."', `publish` = $publish  WHERE `agent_id`='".$id."'";
			//echo $query;	
			if (mysql_query($query)){
				echo $id;
			}else{
			  	echo "0";
			}
		} 
	}elseif( isset($agent) && $agent == "getAgent" ){
		$id 		= $_REQUEST['id'];
		new dbConnect();
		$query = "SELECT * FROM `tagent` WHERE publish = 1 and agent_id = ".$id;
		$res = mysql_query($query);
		echo json_encode(mysql_fetch_object($res));		
	}
?>